﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Loli.Library.WinForm
{
    public class NumberBox : TextBox
    {
        protected override void OnKeyPress(KeyPressEventArgs e)
        {
            base.OnKeyPress(e);

            if ((e.KeyChar < '0' || e.KeyChar > '9') && e.KeyChar != '\b')
            {
                e.Handled = true;
            }
        }

        public int Number
        {
            get
            {
                int number = 0;
                if (int.TryParse(this.Text, out number))
                {
                    return number;
                }
                return number;
            }
            set
            {
                this.Text = Convert.ToString(value);
            }
        }

    }
}
